﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PMG.model;
using PMG.data;
using PMG.data.Tool;
using Spring.Context;
using Spring.Context.Support;

public partial class login : AdminPage
{
    #region 注入对象
    private DaoUserSpring _DaoUserSpring;
    public DaoUserSpring DaoUserSpring
    {
        get { return _DaoUserSpring; }
        set { _DaoUserSpring = value; }
    }
    #endregion

    private IList<USER> listAdmins
    {
        get { return (IList<USER>)ViewState["adlist"]; }
        set{ViewState["adlist"]=value;}
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (CurrAdmin != null)
            Goto();

        if(!IsPostBack)
            BindData();
    }

    #region 验证
    protected void btCommit_Click(object sender, EventArgs e)
    {
        if (txtPwd.Text != string.Empty)
        {
            USER admin = listAdmins[drpAdmin.SelectedIndex];
            //if (txtPwd.Text == SymmetricMethod.Decrypto(admin.UserPwd)) 加密
            if (txtPwd.Text == admin.UserPwd) //不加密
            {
                // 登录并跳转
                Loggin(admin, chkRemeber.Checked);
                Goto();
            }
        }
    }
    #endregion

    #region 绑定
    private void BindData()
    {
        this.listAdmins = DaoUserSpring.SearchByWhere("1=1");

        if (listAdmins == null)
        {
            Response.Write("No any admini data~");
            Response.End();
        }

        this.drpAdmin.DataSource = this.listAdmins;
        this.drpAdmin.DataBind();
    }
    #endregion

    #region 跳转
    private void Goto()
    {
        Response.Redirect("../Admin/OrderMgr/OrderList.aspx");
    }
    #endregion
}
